<div class="content-detail-refer" id="md-wyzx">
    <h3 id="lineZX" class="content-detail-title clearfix">我要咨询<a class="query fr" href="javascript:;">我要提问</a></h3>
    <div class="content">
        <ul id="ask_list">
        </ul>
        <div id="page-list2" class="page-list"></div>
    </div>
</div>
<!-- 咨询弹窗 -->
<div class="faqContainer" id="faqContainer">
    <div class="shadow"></div>
    <div class="faq-wrapper">
        <h3 class="title">我要咨询<a class="close iconfont icon-xhao02" href="javascript:;"></a></h3>
        <div class="con">
            <textarea class="faq-area field_question" name="" id="" cols="20" rows="10" placeholder="请填写你的问题~"></textarea>
            <div class="faq-info-block clearfix">
                <a href="javascript:;" class="submit-btn fr">提交</a>
                <div class="item code fr"><img src="{$cmsurl}captcha" class="ele_checkcode"  onClick="this.src=this.src+'?math='+ Math.random()" width="93" height="36" /></div>
                <span class="item fr">验证码 <input type="text" class="input-text field_checkcode" placeholder="请输入验证码"></span>
                <span class="item fr">联系电话 <input type="text" class="input-text field_phone"  placeholder="请输入手机号" value=""></span>
                <a href="javascript:;" class="lgn-btn">登录账号</a>
            </div>
        </div>
    </div>
</div>

<script>
    $(function(){

        $(".lgn-btn").click(function(){
            $('#is_login_order').removeClass('hide');
        });

        $(".submit-btn").click(function(){
            var question = $("#faqContainer .field_question").val();
            var checkcode = $("#faqContainer .field_checkcode").val();
            var productid = "{$info['id']}";
            var mobile = $("#faqContainer .field_phone").val();

            if(question.length<5){
                layer.alert('{__("question_empty")}', {
                    icon: 5,
                    title: '{__("notice")}'

                });
                return false;
            }
            var mobileReg=/^(\+?0?86\-?)?1[3456789]\d{9}$/;
            if (mobile == '' || !mobileReg.test(mobile)) {
                var msg = mobile.length <1 ? '{__("手机号码不能为空")}' : '{__("请填写正确的手机号码")}';
                layer.alert(msg, {
                    icon: 5,
                    title: '{__("notice")}'

                });
                return false;
            }
            if(checkcode==''){
                layer.alert('{__("checkcode_empty")}', {
                    icon: 5,
                    title: '{__("notice")}'
                });
                return false;
            }

            $.ajax({
                type:'POST',
                url:SITEURL+'pub/ajax_add_question',
                data:{
                    productid:productid,
                    content:question,
                    checkcode:checkcode,
                    //nickname:nickname,
                    typeid:5,
                    questype:0,
                    mobile:mobile
                },
                success:function(data){
                    if(data==1){
                        layer.alert('{__("checkcode_error")}', {
                            icon: 5,
                            title: '{__("notice")}'
                        });
                        //重新加载验证码
                        $("#imgcheckcode").attr('src',"{$cmsurl}captcha?"+Math.random());

                    }else if(data==3){
                        layer.msg('{__("question_success")}',{
                            icon:6,
                            time:2000,
                            end:function () {
                                location.reload();
                            }
                        });
                    }else{
                        layer.alert('{__("question_failure")}', {
                            icon: 5,
                            title: '{__("notice")}'

                        });
                        //重新加载验证码
                        $("#faqContainer .ele_checkcode").attr('src',"{$cmsurl}captcha?"+Math.random());
                    }

                }

            })
        });

        //提问弹窗
        $('#lineZX .query').click(function(){
            var index = layer.open({
                type: 1,
                zIndex:100,
                title: '我要咨询',
                area: ['680px', 'auto'],
                content: $('#faqContainer'),
                skin: 'need-refer-layer'
            });
            $("#faqContainer .close").click(function(){
                layer.close(index);
            });
        });

        //登录状态start
        var username=ST.Storage.getItem('st_username');
        var logintime=ST.Storage.getItem('st_user_logintime');
        var data=ST.Storage.getItem('st_data');
        var req={username:username,logintime:logintime,data:data};
        $.ajax({
            type:"POST",
            data:req,
            url:SITEURL+"member/login/ajax_is_login",
            dataType:'json',
            success:function(data){
                var mobile;
                if(data.status){
                    $(".lgn-btn").hide();
                    $("#faqContainer .field_phone").val(data.user.mobile);

                }else{
                    $(".lgn-btn").show();
                }
            }

        });
        //登录状态end





        //第一次加载问答
        get_more_ask(1);

        //获取更多咨询
        function get_more_ask(page) {
            $.ajax({
                type: 'GET',
                url: SITEURL + 'pub/ajax_get_more_ask',
                dataType: 'json',
                data: {
                    product_id: '{$info['id']}',
                    type_id: 5,
                    page: page
                },
                beforeSend: function () {

                },
                complete: function () {

                },
                success: function (data) {
                    if (data.status)
                    {
                        var html= '';
                        for(var i=0;i<data.list.length;i++)
                        {
                            var row = data.list[i];
                            html+='<li class="clearfix">';
                            html+='<div class="need-refer-left fl">';
                            html+='<div class="w clearfix"><span class="ask">问</span><p>'+row['content']+'</p></div>';
                            html+='<div class="d clearfix"><span class="reply">答</span><p>'+row['replycontent']+'</p></div>';
                            html+='</div>';
                            html+='<div class="need-refer-right fr"><span>'+row['nickname']+'</span><span class="date">'+row['fmt_date']+' '+row['fmt_time']+'</span></div>';
                            html+='</li>';
                        }
                        $("#ask_list").html(html);
                        gen_pager(data.total,page,10)
                    }
                    else
                    {
                    }


                }
            });
        }
        //生成分页
        function gen_pager(total,page,pagesize)
        {
            var page_num = Math.ceil(total/pagesize);
            laypage({
                cont: 'page-list2',
                pages: page_num,
                curr: page,
                skip: true,
                skin: '#2dbb55', //皮肤
                groups: 3,
                first: '首页',
                last: '尾页',
                prev: '上一页',
                next: '下一页',
                jump: function (obj, first)
                {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    if (!first)
                    {
                        get_more_ask(curr);
                    }
                }
            });
        }
    });
</script>